<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Ticket extends Front_Controller {
 	var $siteSetings;
	var $announcement;
	var $lineclass; 
	var $des_tags;		//目的地标签   
	var $TicketClass;
	var $tagsclass;
	function __construct()
	{
		parent::__construct();
		$this->load->helper(array('form', 'url'));
		$this->load->model('front/Frontget_ml');
		$this->load->model('front/Search_m');
		$this->load->model('front/Car_cate_m');
		$this->load->model('front/News_cate_m');		
		$this->load->model('front/Ticket_m');		
		$this->siteSetings=$this->Frontget_ml->get_site_settings();	//获取站点设置
		$this->announcement=$this->Frontget_ml->get_announcement();	//获取网站公告
		$this->lineclass=$this->Frontget_ml->get_lineclass();//获取线路分类
		$this->TicketClass=$this->Frontget_ml->getTicketClass();//获取门票分类
		$this->CityClass=$this->Frontget_ml->getCityClass();//获取城市分类
		$this->newsclass=$this->Frontget_ml->get_newsclass();//获取资讯分类
		$this->tagsclass=$this->Frontget_ml->get_tagsclass();//获取攻略分类
		$this->des_tags=$this->Search_m->get_des_tags();	//获取网站标签
		$this->friend_links=$this->Frontget_ml->get_friend_links();//获取友情链接
		$this->model=19;			//门票model为19
		$this->id=0;				//默认文章id

	}
	public  function index(){	//温情资讯页
				 $RecommendList=$this->Ticket_m->getCommendTicket($this->model,2);//获取推荐门票
				 $HotTicketList=$this->Ticket_m->getHotTicket($this->model,6);				//获取热门资讯
				 $LastTicketList=$this->Ticket_m->getLastTicket($this->model,6);				//获取最新门票
				 $LastTicketOrder=$this->Ticket_m->getLastTicketOrder($this->model,3);				//获取最新订单
				// $TopPicList=$this->News_cate_m->getTopPicList();//获取最新图片资讯
				// $NewsClassList=$this->News_cate_m->getNewsClassList($this->newsclass);//获取资讯分类列表
				$current_title="温泉门票";
				$data=array("id"=>$this->id,"model"=>$this->model,"LastTicketOrder"=>$LastTicketOrder,"CityClass"=>$this->CityClass,"LastTicketList"=>$LastTicketList,"HotTicketList"=>$HotTicketList,"RecommendList"=>$RecommendList,"current_title"=>$current_title,"tagsclass"=>$this->tagsclass,"newsclass"=>$this->newsclass,"TicketClass"=>$this->TicketClass,"siteSetings"=>$this->siteSetings,"lineclass"=>$this->lineclass,"announcement"=>$this->announcement,"friend_links"=>$this->friend_links);
				$this->load->view('inc/header',$data);
				$this->load->view('ticket_v');	
	}
	public  function city($cityId){	//按城市标签显示
		if((int)$cityId){
			$current_title=	$this->CityClass['city_name'][$cityId]."温泉列表";
			$this->load->library('pagination');
			$config['base_url'] = site_url('/ticket/city/'.$cityId.'/');
				
			$Ticketnum= $this->Ticket_m->getTicketnum($cityId);//获取查询条件下的记录总数
				$config['total_rows'] =$Ticketnum;
				$config['per_page'] = 1;
				$config['uri_segment'] = 4;
				$config['full_tag_open'] = '';
				$config['full_tag_close'] = '';
				$config['cur_tag_open']= '&nbsp;<span class="current">';
				$config['cur_tag_close']= '</span>';
				$config['prev_link']= '上一页';
				$config['next_link']= '下一页';
				$config['first_link']= ' 首页';
				$config['last_link']= ' 尾页';
				//	$config['use_page_numbers'] = TRUE;
				$this->pagination->initialize($config);
				$begin_record=$this->uri->segment(4);
				//分页end
				$CityList=$this->Ticket_m->getCityList($cityId,$this->model,$begin_record,$config['per_page']);//获取分类线路列表
			$data=array("cityId"=>$cityId,"id"=>$this->id,"model"=>$this->model,"CityList"=>$CityList,"CityClass"=>$this->CityClass,"current_title"=>$current_title,"tagsclass"=>$this->tagsclass,"newsclass"=>$this->newsclass,"TicketClass"=>$this->TicketClass,"siteSetings"=>$this->siteSetings,"lineclass"=>$this->lineclass,"announcement"=>$this->announcement,"friend_links"=>$this->friend_links);
			$this->load->view('inc/header',$data);
			$this->load->view('ticketCity_V');	
		}else{
			redirect(base_url());	//参数错误
		}				
	}
	public  function show($tid){	//获取指定id文章信息
		if((int)$tid){
			$TicketInfo=$this->Ticket_m->getTicketInfo($tid);	//获取指定id文章信息
			if($TicketInfo){
				$cityId=explode("-",str_replace(",","",$TicketInfo["info"][0]->destination));//城市id
				//	print_r($cateid);
				if(empty($TicketInfo["annex"])){
					$pics="img/nopic.jpg";
				}else{	
					$pics=$this->platform->file_url($TicketInfo["annex"][0]->folder.'/'.$TicketInfo["annex"][0]->name.'.'.$TicketInfo["annex"][0]->type);
				}				
				$current_title=$TicketInfo["info"][0]->ticketTitle;
				$LastTicketOrder=$this->Ticket_m->getLastTicketOrder($this->model,3);				//获取最新订单
				$data=array("LastTicketOrder"=>$LastTicketOrder,"current_title"=>$current_title,"pics"=>$pics,"CityClass"=>$this->CityClass,"tagsclass"=>$this->tagsclass,"newsclass"=>$this->newsclass,"TicketClass"=>$this->TicketClass,"id"=>$tid,"des_tags"=>$this->des_tags,"siteSetings"=>$this->siteSetings,"lineclass"=>$this->lineclass,"TicketInfo"=>$TicketInfo,"cityId"=>$cityId[0],"announcement"=>$this->announcement,"friend_links"=>$this->friend_links);
		
				$this->load->view('inc/header',$data);
				$this->load->view('ticketShow_v');
			}else{
				redirect(base_url());	//无改文章
				
			}
		}else{
			redirect(base_url());	//参数错误
		}
	}	
	public  function ticketOrder($tid){	//订单页
		if((int)$tid && (int)$this->uri->segment(4)){
			$TicketInfo=$this->Ticket_m->getTicketInfo($tid);	//获取指定id文章信息
			$ordernum=(int)$this->uri->segment(4);
				//$cityId=explode("-",str_replace(",","",$TicketInfo["info"][0]->destination));//城市id
				//	print_r($cateid);
			if($TicketInfo){
				$current_title=$TicketInfo["info"][0]->ticketTitle."门票预订";
				$LastTicketOrder=$this->Ticket_m->getLastTicketOrder($this->model,3);				//获取最新订单
				$data=array("LastTicketOrder"=>$LastTicketOrder,"TicketInfo"=>$TicketInfo,"current_title"=>$current_title,"ordernum"=>$ordernum,"CityClass"=>$this->CityClass,"tagsclass"=>$this->tagsclass,"newsclass"=>$this->newsclass,"TicketClass"=>$this->TicketClass,"id"=>$tid,"des_tags"=>$this->des_tags,"siteSetings"=>$this->siteSetings,"lineclass"=>$this->lineclass,"announcement"=>$this->announcement,"friend_links"=>$this->friend_links);
		
				$this->load->view('inc/header',$data);
				$this->load->view('ticketOrder_v');
			}

		}else{
			redirect(base_url());	//参数错误
		}
	}	
	public  function orderSave(){	//订单保存
		$this->_orderSave_post();
	}
	public  function _orderSave_post(){	//订单保存
		//print_r($_POST);
		$tid      		 = $this->input->post("tid");					//门票id
		$pricePer  		 = $this->input->post("pricePer");				//单价
		$orderNum  		 = $this->input->post("orderNum");				//订单数量
		$departureDate   = $this->input->post("departureDate");			//出游日期
		$RealName     	 = $this->input->post("RealName");				//联系人
		$phone     		 = $this->input->post("phone");					//手机
		$Tel     		 = $this->input->post("Tel");					//电话
		$qqNum     		 = $this->input->post("qqNum");					//QQ
		$Email     		 = $this->input->post("Email");					//QQ
		$Remark     	 = $this->input->post("Remark");				//备注
		$oid=0;
		if(is_numeric($tid) && is_numeric($pricePer) && is_numeric($orderNum) && strtotime($departureDate)){ 
			$status   	 = $this->Ticket_m->saveTicketOrder($tid,$pricePer,$orderNum,$departureDate,$RealName,$phone,$Tel,$qqNum,$Email,$Remark);	
			if($status["success"]){
				redirect(site_url("/ticket/orderSuccess/".$status["oid"]));	//跳转		
			}
			
		}else{
			redirect(base_url());	//参数错误
		}	
	}
	public  function orderSuccess($oid){	//订单成功页
		if((int)$oid){
			$OrderInfo   = $this->Ticket_m->getOrderInfo($oid);
			$current_title="订单成功";
			$data=array("current_title"=>$current_title,"Email"=>$OrderInfo[0]->Email,"qqNum"=>$OrderInfo[0]->qqNum,"Tel"=>$OrderInfo[0]->Tel,"phone"=>$OrderInfo[0]->phone,"departureDate"=>$OrderInfo[0]->departureDate,"pricePer"=>$OrderInfo[0]->pricePer,"RealName"=>$OrderInfo[0]->RealName,"orderNum"=>$OrderInfo[0]->orderNum,"CityClass"=>$this->CityClass,"tagsclass"=>$this->tagsclass,"newsclass"=>$this->newsclass,"TicketClass"=>$this->TicketClass,"id"=>$OrderInfo[0]->tid,"des_tags"=>$this->des_tags,"siteSetings"=>$this->siteSetings,"lineclass"=>$this->lineclass,"announcement"=>$this->announcement,"friend_links"=>$this->friend_links);			
			$this->load->view('inc/header',$data);
			$this->load->view('ticketOrderSuccesss_v');			
		}	
	}
}